package teleradiologia.service;

import java.util.List;

import teleradiologia.domain.Address;
import teleradiologia.domain.Customer;
import teleradiologia.domain.Radiologylab;
import teleradiologia.repository.AddressDao;
import teleradiologia.repository.CustomerDao;
import teleradiologia.repository.RadiologylabDao;

public class RadiologylabManipulatorImpl implements RadiologylabManipulator {

	private RadiologylabDao radiologylabDao;
	private AddressDao addressDao;
	private CustomerDao customerDao;


	@Override
	public void delete(Radiologylab radiologylab) {
		this.radiologylabDao.delete(radiologylab);
		this.addressDao.delete(radiologylab.getAddress());
	}

	@Override
	public List<Radiologylab> getAll() {
		return this.radiologylabDao.getAll();
	}

	@Override
	public Radiologylab getByKrsnumber(String krsnumber) {
		return this.radiologylabDao.getByKrsnumber(krsnumber);
	}


	@Override
	public void update(Radiologylab radiologylab) {
		this.addressDao.update(radiologylab.getAddress());
		this.radiologylabDao.update(radiologylab);
	}


	@Override
	public String createRadiologylab(Radiologylab radiologylab,
			Address address, Customer customer) {
		
		long patientId = this.addressDao.create(address);
		
		long customerId = this.customerDao.create(customer);
		
		radiologylab.setAddress(this.addressDao.getById(patientId));
		radiologylab.setCustomer(this.customerDao.getById(customerId));
		
		return this.radiologylabDao.create(radiologylab);
	}
	
	@Override
	public void setRadiologylabDao(RadiologylabDao radiologylabDao) {
		this.radiologylabDao = radiologylabDao;
	}

	@Override
	public void setAddressDao(AddressDao addressDao) {
		this.addressDao = addressDao;
	}
	
	public void setCustomerDao(CustomerDao customerDao) {
		this.customerDao = customerDao;
	}
}
